/*j07c8riwYnz20MYibuDbtKX3aAHwVScUH0o1jr9bLDbrPowwFtbWCjxiLloLZa12*/
import { ajax, cardCache } from 'nc-lightapp-front';
import constants from '../../constants';
import ampub from 'ampub';

import { listQueryBackHandler } from './commonHandler';
import { setBatchBtnsEnable } from './rowSelected';

const { utils: { listUtils: { setListValue } } } = ampub;

const { PAGE_CODE, URL, pk2ClientKeyMap, assetDataSource, AREA: { LIST: { GRID_AREA: tableId } } } = constants;

export default function(props, config, pks) {
	doQueryByPks(props, pks);
}

//根据pks进行查询
const doQueryByPks = (props, pks) => {
	//先把 pks(实际上是 pk_cardhistory)转为clientKey
	let keys = cardCache.getDefData(pk2ClientKeyMap, assetDataSource);

	let clientKeys = [];
	for (let pk of pks) {
		clientKeys.push(keys[pk]);
	}

	let data = {
		allpks: clientKeys,
		pagecode: PAGE_CODE.LIST
	};
	ajax({
		url: URL.QUERY_LIST_BYPKS,
		data: data,
		success: (res) => {
			setListValue.call(this, props, res, tableId);
			setBatchBtnsEnable.call(this, props, tableId);
		},
		error: (err) => {
			listQueryBackHandler.error(props, err);
		}
	});
};

/*j07c8riwYnz20MYibuDbtKX3aAHwVScUH0o1jr9bLDbrPowwFtbWCjxiLloLZa12*/